﻿@{
    ViewBag.Title = "图标管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

<div class="easyui-layout" data-options="fit:true" scroll="no">
    <div data-options="region:'center',noheader:true,border:false">
        <table id="dgIcon"></table>
    </div>
</div>
<div id="tbar">
    <div class="tbar">
        <div class="z-toolbar">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow_refresh',plain:true" onclick="ToolbarRefresh();">刷新</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="ToolbarAdd();">增加</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="ToolbarEdit();">编辑</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cross',plain:true" onclick="ToolbarRemove();">删除</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="ToolbarUnselect();">取消选中</a>
        </div>
    </div>
</div>
@section PageSpecificScript{
    <script type="text/javascript">
        var dgIcon;//图标
        $(document).ready(function () {
            dgIcon = $("#dgIcon").datagrid({
                url: '/Admin/Sys_Icons/GetIconsByPage',
                method: 'get',
                idField: 'IconID',
                fit: true,
                fitColumns: true,
                rownumbers: true,
                striped: true,
                pagination: true,
                singleSelect: true,
                toolbar: '#tbar',
                pageSize: 20,
                pageList: [10, 20, 30, 40, 50],
                frozenColumns: [[
                    { field: 'IconID', title: 'IconID', hidden: true }
                ]],
                columns: [[
                        { field: 'IconName', title: '名称', width: 80, halign: 'center', align: 'center', },
                        {
                            field: 'IconTitle', title: '图标', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                                return '<span class="icon ' + row.IconTitle + '">&nbsp;</span>';
                            }
                        },
                        { field: 'IconType', title: '类型', width: 80, halign: 'center', align: 'center', formatter: function (value, row, index) { if (value == 0) return '通用'; else if (value == 1) return 'System'; else return '用户' } },
                        { field: 'IconOrder', title: '排序', width: 80, halign: 'center', align: 'center', },
                        {
                            field: 'IconCreateTime', title: '创建日期', width: 80, halign: 'center', align: 'center',
                            formatter: function (value, row, index) {
                                if (value) {
                                    return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
                                }
                            }
                        },

                ]],
                onDblClickRow: function (rowIndex, rowData) {
                    if (editRow != undefined) {
                        dgIcon.datagrid('endEdit', editRow);
                    } else {
                        dgIcon.datagrid('beginEdit', rowIndex);
                        editUser = rowIndex;
                        dgIcon.datagrid('selectRow', editUser);
                    }
                },
                onRowContextMenu: function (e, rowIndex, rowData) {
                    e.preventDefault();
                    $(this).datagrid("unselectAll");
                    $(this).datagrid("selectRow", rowIndex);
                    $("#menu").menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }
            });
        })
        /**刷新图标**/
        function ToolbarRefresh() {
            dgIcon.datagrid("load");
        }
        /**增加图标**/
        function ToolbarAdd() {
            showAppendView();
        }
        /**编辑图标**/
        function ToolbarEdit() {
            showEditView();
        }
        /**删除图标**/
        function ToolbarRemove() {
            removeUser();
        }
        /**取消选中图标**/
        function ToolbarUnselect() {
            dgIcon.datagrid("unselectAll");
        }
        /**分配权限**/
        function ToolbarAllotPer() {
            AllotPer();
        }
        /**分配用户**/
        function ToolbarAllotUser() {
            AllotUser();
        }
        /*打开添加权限信息的页面*/
        function showAppendView() {
            $.validateUrl('/Admin/Sys_Icons/EditView', append, xz.dealWith, 'GET');
        }
        /*增加图标信息*/
        function append() {
            var pAdd = xz.dialog({
                title: '新增图标',
                width: 650,
                height: 200,
                iconCls: 'icon-add',
                href: '/Admin/Sys_Icons/EditView',
                buttons: [{
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        var f = pAdd.find('form');
                        f.form('submit', {
                            url: '/Admin/Sys_Icons/AddIcon',
                            success: function (jsonData) {
                                jsonData = $.parseJSON(jsonData);
                                $.procAjaxMsg(jsonData, function () {
                                    pAdd.dialog('close');
                                    dgIcon.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        pAdd.dialog('close');
                    }
                }]
            })
        }
        /*编辑图标信息*/
        function showEditView() {
            $.validateUrl('/Admin/Sys_Icons/EditView', edit, xz.dealWith, 'Get');
        }
        /*修改图标信息*/
        function edit() {
            var node = dgIcon.datagrid("getSelected");
            if (node) {
                var pAdd = xz.dialog({
                    title: '修改图标',
                    width: 650,
                    height: 200,
                    iconCls: 'icon-edit',
                    href: '/Admin/Sys_Icons/EditView',
                    buttons: [{
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit', {
                                url: '/Admin/Sys_Icons/EditIcon',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgIcon.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var IconID = f.find('input[name=IconID]');
                        var IconCreateTime = f.find('input[name=IconCreateTime]');
                        var IconName = f.find('input[name=IconName]');
                        var IconTitle = f.find('input[name=IconTitle]');
                        var IconType = f.find('input[name=IconType]');
                        var IconOrder = f.find('input[name=IconOrder]');

                        window.setTimeout(function () {
                            uLoginName.focus();
                        }, 100);

                        /*把选中的图标信息绑定到对应的表单上*/
                        f.form('load', node);
                    }
                })
            } else {
                xz.messageAlert("提示", "请选择要修改的图标", "error");
            }
        }
        /*删除图标*/
        function removeUser() {
            var rows = dgIcon.datagrid("getSelected");
            if (rows) {
                xz.messageConfirm('询问', '你确定要删除【' + rows.IconName + '】吗?', function (b) {
                    if (b) {
                        $.ajax({
                            type: 'POST',
                            url: '/Admin/Sys_Icons/DelIcon',
                            data: {
                                IconID: rows.IconID
                            },
                            cache: false,
                            dataType: 'JSON',
                            success: function (jsonData) {
                                $.procAjaxMsg(jsonData, function () {
                                    dgIcon.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                });
            }
        }
    </script>
}